package com.hmall.item.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import org.apache.ibatis.annotations.Mapper;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


@Mapper
public interface ItemMapper extends BaseMapper<Item> {
    @Update("update tb_item set stock = stock - ${num} where id = #{itemId}")
    int deduct(@Param("itemId") Long itemId, @Param("num") int num);

    @Update("update tb_item set stock = stock + ${num} where id = #{itemId}")
    int refund(@Param("itemId") Long itemId, @Param("num") int num);

    @Select("select * from tb_item where id = #{id}")
    Item selectItemById(Long id);

    @Insert("insert into tb_item (name, category, brand, price, stock, spec, image, isAD,create_time,update_time) " +
            "values (#{name}, #{category}, #{brand}, #{price}, #{stock}, #{spec}, #{image}, #{isAD},#{createTime},#{updateTime})")
    int insertProduct(Item item);
}
